package com.android.test.model;

import java.util.ArrayList;

import com.android.test.view.DetailView;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class EntryAdapter extends ArrayAdapter<Entry> {
	
	private Context mContext;
	
	public EntryAdapter(Context context) {
		super(context, 0);
		mContext = context;
	}

	@Override
	public Entry getItem(int position) {
		if ((position > getCount()) || position < 0) {
			throw new IllegalArgumentException();
		}
		return super.getItem(position);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Entry entry = getItem(position);
		if (convertView == null) {			
			DetailView itemView = new DetailView(mContext);
			itemView.setData(entry);
			convertView = itemView.getDetailView();
		}else {
			if (convertView instanceof DetailView) {
				((DetailView)convertView).setData(entry);
			}
		}
		
		return convertView;
	}
	
	public void add(ArrayList<OrgDetailInfo> list) {
		synchronized (list) {
			for (Entry entry : list) {
				add(entry);
			}
		}
	}
}
